/**
 * @file   PacketHeader.h
 * @author Djuro Drljaca (djurodrljaca@gmail.com)
 * @date   2014-04-20
 * @brief  DON packet header object.
 *
 * Copyright 2014  Djuro Drljaca (djurodrljaca@gmail.com)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef DON_CORE_PACKET_PACKETHEADER_H
#define DON_CORE_PACKET_PACKETHEADER_H

#include <DON/Core/Packet/PacketType.h>

namespace DON
{
namespace Core
{
namespace Packet
{

/**
 * @brief The PacketHeader class
 */
class LIBDONQT4CORESHARED_EXPORT PacketHeader
{
public:
    /**
     * @brief Constructor
     */
    PacketHeader();

    /**
     * @brief Constructor
     * @param source Packet's Source address
     * @param destination Packet's Destination address
     * @param packetType Packet type
     * @param sequence Sequence number
     * @param payloadLength Payload length
     * @param payloadChecksum Payload checksum
     */
    PacketHeader(const quint16 source,
                 const quint16 destination,
                 const PacketType packetType,
                 const quint16 sequence,
                 const quint16 payloadLength,
                 const quint16 payloadChecksum);

    /**
     * @brief Copy constructor
     * @param other Object to be copied
     */
    PacketHeader(const PacketHeader &other);

    /**
     * @brief Destructor
     */
    ~PacketHeader();

    /**
     * @brief Assignment operator
     * @param other Object to be copied
     * @return This object
     */
    PacketHeader & operator=(const PacketHeader &other);

    /**
     * @brief Get packet's Source address
     * @return Packet's Source address
     */
    quint16 getSource() const;

    /**
     * @brief Get packet's Destination address
     * @return Packet's Destination address
     */
    quint16 getDestination() const;

    /**
     * @brief Get packet type
     * @return Packet type
     */
    PacketType getPacketType() const;

    /**
     * @brief Get sequence number
     * @return Sequence number
     */
    quint16 getSequence() const;

    /**
     * @brief Get payload length
     * @return Payload length
     */
    quint16 getPayloadLength() const;

    /**
     * @brief Get payload checksum
     * @return Payload checksum
     */
    quint16 getPayloadChecksum() const;

    /**
     * @brief Parse packet header from binary data
     * @param data Binary data
     * @param startIndex Start index of the header data
     * @retval true Success
     * @retval false Error
     */
    bool fromBinary(const QByteArray &data, const int startIndex = 0);

    /**
     * @brief Create binary representation of the packet header
     * @return Binary data
     */
    QByteArray toBinary() const;

private:
    class Private;
    Private *d;
};

}
}
}

#endif // DON_CORE_PACKET_PACKETHEADER_H
